Update dependency erb to v6.0.4 [SECURITY]#640
Merged
Taucher2003 merged 1 commit intomainfrom Apr 24, 2026
Merged
Conversation
GitLab Pipeline ActionGeneral informationLink to pipeline: https://gitlab.com/code0-tech/development/reticulum/-/pipelines/2477853001 Status: Passed Job summariesdocs:previewDocumentation preview available at https://code0-tech.gitlab.io/-/development/telescopium/-/jobs/14080704940/artifacts/out/index.html generate-environmentRETICULUM_CONTAINER_VERSION=0.0.0-experimental-2477853001-24d37f073337f2c78fb54a0ce349cc0e50265b01 |
Taucher2003
approved these changes
Apr 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR contains the following updates:
6.0.3→6.0.4ERB has an @_init deserialization guard bypass via def_module / def_method / def_class
CVE-2026-41316 / GHSA-q339-8rmv-2mhv
More information
Details
Summary
Ruby 2.7.0 (before ERB 2.2.0 was published on rubygems.org) introduced an
@_initinstance variable guard inERB#resultandERB#runto prevent code execution when an ERB object is reconstructed viaMarshal.load(deserialization). However, three other public methods that also evaluate@srcviaeval()were not given the same guard:ERB#def_methodERB#def_moduleERB#def_classAn attacker who can trigger
Marshal.loadon untrusted data in a Ruby application that haserbloaded can useERB#def_module(zero-arg, default parameters) as a code execution sink, bypassing the@_initprotection entirely.Details
The @_init Guard
In
ERB#initialize, the guard is set:In
ERB#resultandERB#run, the guard is checked beforeeval(@​src):When an ERB object is reconstructed via
Marshal.load,@_initis eithernil(not set during marshal reconstruction) or an attacker-controlled value. SinceERB.singleton_classcannot be marshaled, the attacker cannot set@_initto the correct value, andresult/runcorrectly refuse to execute.The Bypass
ERB#def_method,ERB#def_module, andERB#def_classall reacheval(@​src)without checking@_init:def_moduleanddef_classaccept zero arguments (all parameters have defaults), making them callable through deserialization gadget chains that can only invoke zero-arg methods.Method wrapper breakout
def_methodwraps@srcin a method definition:"def erb\n" + @​src + "\nend\n". Code inside a method body only executes when the method is called, not when it's defined. However, by setting@srcto begin withend\n, the attacker closes the method definition early. Code after the firstendexecutes immediately atmodule_evaltime:Proof of Concept
Minimal (ERB only)
Marshal deserialization (ERB + ActiveSupport)
When combined with
ActiveSupport::Deprecation::DeprecatedInstanceVariableProxyas a method dispatch gadget, this achieves RCE viaMarshal.load:Chain:
Marshal.loadreconstructs a Hash with aDeprecatedInstanceVariableProxyas key.hashon the proxy.hashis undefined ->method_missing(:hash)-> dispatches toERB#def_moduledef_module->def_method->module_eval(eval(src))-> breakout ->system('id')Verified on: Ruby 3.3.8 / RubyGems 3.6.7 / ActiveSupport 7.2.3 / ERB 6.0.1
Impact
Scope
Any Ruby application that calls
Marshal.loadon untrusted data AND has botherbandactivesupportloaded is vulnerable to arbitrary code execution. This includes:Marshal.loadfor caching, data import, or IPCSeverity justification
The
@_initguard was the recognized last line of defense against ERB being used as a deserialization gadget. Prior gadget chain research -- including Luke Jahnke's November 2024 Ruby 3.4 chain (nastystereo.com) and vakzz's 2021 Universal Deserialization Gadget -- pursued entirely different approaches (Gem::SpecFetcher, UncaughtThrowError, TarReader+WriteAdapter) without exploring the ERB def_method/def_module path. Thedef_modulebypass is simpler and more direct than all previous chains, and was not addressed by the subsequent patches to Ruby 3.4 or RubyGems 3.6.This bypass renders the @_init mitigation ineffective across all ERB versions from 2.2.0 through 6.0.3 (latest as of April 2026). Combined with the DeprecatedInstanceVariableProxy gadget (present in all ActiveSupport versions through 7.2.3), this constitutes a universal RCE gadget chain for Ruby 3.2+ applications using Rails.
Details
Gadget chain history
Six generations of Ruby Marshal gadget chains have been discovered (2018-2026). Each bypassed the previous round of mitigations:
Patches
The problem has been patched at the following ERB versions. Please upgrade your erb.gem to any one of them.
Details
Add the
@_initcheck todef_method. Sincedef_moduleanddef_classboth delegate todef_method, this single change covers all three bypass paths:Severity
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:HReferences
This data is provided by the GitHub Advisory Database (CC-BY 4.0).
Configuration
📅 Schedule: (UTC)
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR was generated by Mend Renovate. View the repository job log.